package handler

import (
	"strconv"

	"github.com/gin-gonic/gin"

	"awesomeProject/app/request"
	"awesomeProject/app/response"
	"awesomeProject/app/service"
)

type LoginlogHandler struct{}

var (
	loginlogSrv service.LoginlogSrv
)

// Pagination 日志列表（分页）
func (r *LoginlogHandler) Pagination(ctx *gin.Context) {
	var req request.LoginlogPagination
	_ = ctx.Bind(&req)

	response.Result(ctx, loginlogSrv.Pagination(req))
	return
}

// Show 日志详情
func (r LoginlogHandler) Show(ctx *gin.Context) {
	id, _ := strconv.Atoi(ctx.Param("id"))
	err, loginlog := loginlogSrv.FindByID(uint(id))
	if err != nil {
		response.Result(ctx, response.ErrRecordNotFound)
		return
	}

	response.Result(ctx, response.OK.WithData(loginlog))
}

// Del 删除
func (r LoginlogHandler) Del(ctx *gin.Context) {
	id, _ := strconv.Atoi(ctx.Param("id"))
	response.Result(ctx, loginlogSrv.Del(uint(id)))
	return
}